package com.scott.ch03.selector;

import com.scott.ch24.ch03.bean.Person;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class ScottImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    
    /**
     * 方法描述:
     * @author: 黄后林
     * @date: 2021/11/22 0:15 
     * @param importingClassMetadata
     * @param registry
     */
    @Override
    public  void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                         BeanDefinitionRegistry registry) {

        boolean student = registry.containsBeanDefinition("com.scott.ch03.bean.Student");
        boolean teacher = registry.containsBeanDefinition("com.scott.ch03.bean.Teacher");

        if(student && teacher){

            RootBeanDefinition root = new RootBeanDefinition(Person.class);
            // 自定义1个bean
            registry.registerBeanDefinition("person",root);

        }

    }


}
